package training;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_8_1_Training {
    //杨辉三角
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> arr =new ArrayList<>();
        generate(numRows,arr);
        return arr;
    }
    // 返回当前行的所有元素
    public List<Integer> generate(int numRows,List<List<Integer>> arr ){
        if(numRows==1) {
            List current =List.of(1);
            arr.add(current);
            return current;
        }
        //上一行
        List<Integer> front =generate(numRows-1,arr);
        //接收当前行
        List<Integer> current=new ArrayList<>();
        current.add(1);
        for(int i=1;i<numRows-1;i++){
            current.add(front.get(i-1)+front.get(i));
        }
        current.add(1);
        arr.add(current);
        return current;
    }

    //验证IP地址
    public String validIPAddress(String IP) {
        if (IP == null) {
            return "Neither";
        }

        String regex0 = "(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])";
        String regexIPv4 = regex0 + "(\\." + regex0 + "){3}";
        String regex1 = "([\\da-fA-F]{1,4})";
        String regexIPv6 = regex1 + "(:" + regex1 + "){7}";

        String result = "Neither";
        if (IP.matches(regexIPv4)) {
            result = "IPv4";
        } else if (IP.matches(regexIPv6)) {
            result = "IPv6";
        }
        return result;
    }
}
